<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <!--    查询对话框-->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="440px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
        style="margin-left: 55px"
      >
        <el-col :span="24">
          <el-form-item label="模具编号" prop="mjmMjbh">
            <el-input
              v-model="queryParams.mjmMjbh"
              placeholder="请输入模具编号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="模具名称" prop="mjmMjmc">
            <el-input
              v-model="queryParams.mjmMjmc"
              placeholder="请输入模具名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="模具状态" prop="mjmMjzt">
            <el-select
              v-model="queryParams.mjmMjzt"
              placeholder="请选择模具状态"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in mjmMjztOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <el-row :gutter="20" style="display: flex">
      <!--模具数据-->
      <div>
        <div class="head-container">
          <el-tree
            style="
              width: 350px;
              height: 830px;
              overflow: hidden;
              overflow-y: scroll;
            "
            v-if="treeLoad"
            :data="deptOptions"
            :props="defaultProps"
            ref="tree"
            node-key="id"
            :default-expanded-keys="expandedKey"
            @node-click="handleNodeClick"
          />
        </div>
      </div>
      <div style="overflow: hidden">
        <el-row :gutter="10" style="position: relative; margin-bottom: 5px">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-search"
              size="mini"
              @click="handleSearch"
              >搜索</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['project:mjmMstr:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['project:mjmMstr:edit']"
            >
              修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="upLoad"
              v-hasPermi="['project:mjmMstr:upload']"
            >
              上传
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['project:mjmMstr:remove']"
            >
              删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              :loading="exportLoading"
              @click="handleExport"
              v-hasPermi="['project:mjmMstr:export']"
            >
              导出
            </el-button>
          </el-col>
          <el-col :span="2.2" style="position: absolute; right: 35px; top: 0">
            <Page
              style="margin-right: 0px"
              :current="queryParams.pageNum"
              :page-size="queryParams.pageSize"
              :total="total"
              @on-change="pageChange"
              simple
            ></Page>
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table
          v-loading="loading"
          size="mini"
          :data="mjmMstrList"
          :height="tableH"
          border
          stripe
          :cell-style="iCellStyle"
          highlight-current-row
          :row-style="{ padding: '0px' }"
          :header-row-style="{ padding: '2px 0' }"
          :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
          @row-click="clickListFile"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="模具编号"
            show-overflow-tooltip
            width="150"
            prop="mjmMjbh"
          />
          <el-table-column
            label="模具名称"
            width="180"
            show-overflow-tooltip
            prop="mjmMjmc"
          />
          <el-table-column
            label="文件份数"
            align="center"
            prop="mjmFileCount"
          />
          <el-table-column
            label="模具尺寸"
            width="130"
            show-overflow-tooltip
            prop="mjmMjgg"
          />
          <el-table-column
            label="吨位"
            align="center"
            width="80"
            prop="mjmDw"
          />
          <el-table-column label="共模描述" align="center" prop="mjmXsms" />
          <el-table-column label="穴数" align="center" prop="mjmXs" />
          <el-table-column label="成型时间" align="center" prop="mjmCxsj" />
          <el-table-column label="模具存放位置" align="center" prop="mjmCwdm" />
          <el-table-column label="模具状态" align="center" prop="mjmMjzt">
            <template #default="scope">
              <dict-tag :options="mjmMjztOptions" :value="scope.row.mjmMjzt" />
            </template>
          </el-table-column>
          <el-table-column
            label="模具配套设备"
            width="180"
            show-overflow-tooltip
            align="center"
            prop="mjmMjsb"
          />
          <el-table-column
            label="到厂时间"
            align="center"
            prop="mjmDcrq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.mjmDcrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>

          <el-table-column
            label="隶属客户"
            align="center"
            width="120"
            prop="mjmKhid"
          >
            <template #default="scope">
              <dict-tag :options="mjmKhOptions" :value="scope.row.mjmKhid" />
            </template>
          </el-table-column>
          <el-table-column
            label="模具供应商"
            width="150"
            show-overflow-tooltip
            prop="mjmMjcs"
          />
          <el-table-column
            label="热流道供应商"
            width="150"
            align="center"
            show-overflow-tooltip
            prop="mjmRldcs"
          />
          <el-table-column
            label="备注"
            width="200"
            show-overflow-tooltip
            prop="mjmDesc"
          />
          <el-table-column label="总合模数" align="center" prop="mjmCount" />
          <el-table-column label="已保养数" align="center" prop="mjmYbys" />
          <el-table-column label="待保养数" align="center" prop="mjmDbys" />
          <el-table-column label="保养周期" align="center" prop="mjmByzq" />
          <el-table-column label="使用寿命" align="center" prop="mjmSysm" />
          <el-table-column
            label="最近使用机台"
            width="130"
            align="center"
            prop="mjmNewjtbh"
          />
          <el-table-column label="建立人员" align="center" prop="createBy" />
          <el-table-column
            label="建立日期"
            align="center"
            prop="createTime"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="更改人员" align="center" prop="updateBy" />
          <el-table-column
            label="更改日期"
            align="center"
            prop="updateTime"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="120"
            fixed="right"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button size="mini" type="text" @click="resume(scope.row)"
                >模具履历表</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <el-tabs v-model="activeTab">
          <el-tab-pane label="维修保养记录" name="first">
            <el-table
              v-loading="loading"
              border
              stripe
              highlight-current-row
              :row-style="{ padding: '0px' }"
              :cell-style="{ padding: '0px 0' }"
              :header-row-style="{ padding: '2px 0' }"
              :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
              :height="tableHChild"
              :data="mjmBylXmlList"
              @selection-change="handleSelectionChange"
            >
              <el-table-column
                label="#"
                type="index"
                width="40"
                align="center"
              />
              <el-table-column
                label="记录类型"
                width="100"
                align="center"
                prop="recordType"
              />
              <el-table-column
                label="开始时间"
                width="130"
                align="center"
                prop="beginDate"
              />
              <el-table-column
                label="结束时间"
                width="130"
                align="center"
                prop="endDate"
              />
              <el-table-column
                label="工时（h）"
                width="100"
                align="center"
                prop="workingHours"
              />
              <el-table-column
                label="状态"
                width="80"
                align="center"
                prop="state"
              />
              <el-table-column
                label="问题分类"
                width="110"
                align="center"
                prop="problemType"
              />
              <el-table-column
                label="问题原因描述"
                width="130"
                align="center"
                prop="problemDetail"
              />
              <el-table-column
                label="责任人员"
                width="80"
                align="center"
                prop="personnel"
              />
              <!--              <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
                <template #default="scope">
                  <el-button size="mini" type="text">附件</el-button>
                  <el-button size="mini" type="text">保全记录</el-button>
                </template>
              </el-table-column>-->
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="上传文件记录" name="second">
            <el-table
              v-loading="loading"
              border
              stripe
              highlight-current-row
              :row-style="{ padding: '0px' }"
              :cell-style="{ padding: '0px 0' }"
              :header-row-style="{ padding: '2px 0' }"
              :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
              :data="mjmFileList"
              :height="tableHChild"
              @selection-change="handleSelectionChange"
            >
              <el-table-column
                label="#"
                type="index"
                width="40"
                align="center"
              />
              <el-table-column
                label="文件编号"
                width="150"
                align="center"
                prop="docDjbh"
              />
              <el-table-column
                label="文件名称"
                width="150"
                align="center"
                prop="docName"
              />
              <el-table-column
                label="备注"
                width="100"
                align="center"
                prop="docDesc"
              />
              <el-table-column
                label="建立人员"
                width="100"
                align="center"
                prop="createBy"
              />
              <el-table-column
                label="建立日期"
                width="150"
                align="center"
                prop="createTime"
              />
              <el-table-column
                label="操作"
                align="center"
                width="100"
                class-name="small-padding fixed-width"
              >
                <template #default="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleImgLook(scope.row)"
                    v-hasPermi="['project:mjmMstr:lookFile']"
                    >查看</el-button
                  >
                  <el-button
                    size="mini"
                    type="text"
                    v-hasPermi="['project:mjmMstr:delete']"
                    @click="handleFileDelete(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-row>
    <el-dialog
      v-model="openResume"
      :rules="rules"
      :close-on-click-modal="false"
      :before-close="handleClose"
      width="1300px"
      append-to-body
    >
      <div class="divmjlvb">
        <h1 style="width: 1200px; text-align: center; display: inline-block">
          武汉市衡德实业有限公司
        </h1>
        <div style="display: inline-block; width: 1200px">
          <p style="width: 1200px; text-align: center; font-size: 20px">
            模具履历表
          </p>
          <div style="text-align: right">
            <span>选择日期</span>
            <el-select
              v-model="formYearAndMonth.recentYear"
              @change="yearChange"
              size="mini"
              placeholder="请选择"
            >
              <el-option
                v-for="item in years"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <el-select
              v-model="formYearAndMonth.recentMonth"
              @change="monthChange"
              size="mini"
              placeholder="请选择"
            >
              <el-option
                v-for="item in months"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </div>
        </div>

        <table class="tabJbxx">
          <tr>
            <td style="width: 200px">模具名称</td>
            <td style="width: 200px">{{ mjmMstrProList.mjmMjmc }}</td>
            <td style="width: 200px">模具编号</td>
            <td style="width: 200px">{{ mjmMstrProList.mjmMjbh }}</td>
            <td style="width: 200px">模具穴数</td>
            <td style="width: 200px">{{ mjmMstrProList.mjmXs }}</td>
          </tr>
          <tr>
            <td>进厂日期</td>
            <td>{{ mjmMstrProList.mjmDcrq }}</td>
            <td>制造厂家</td>
            <td>{{ mjmMstrProList.mjmMjcs }}</td>
            <td>机台吨位</td>
            <td>{{ mjmMstrProList.mjmDw }}</td>
          </tr>
          <tr>
            <td>模具尺寸</td>
            <td>{{ mjmMstrProList.mjmMjgg }}</td>
            <td>产品名称</td>
            <td>{{ mjmMstrProList.mjmCpmc }}</td>
            <td>客户编码</td>
            <td>{{ mjmMstrProList.mjmKhbm }}</td>
          </tr>
        </table>

        <p style="width: 1200px; text-align: center">模具生产运行履历</p>
        <div style="display: inline-block">
          <el-table
            style="width: 602px"
            v-loading="loading"
            border
            stripe
            highlight-current-row
            :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
            :data="mjmProductionList"
            height="414px"
          >
            <el-table-column
              label="日期"
              width="150"
              align="center"
              prop="sdmRq"
            />
            <el-table-column
              label="日生产模数"
              width="150"
              align="center"
              prop="sdmHmcs"
            />
            <el-table-column
              label="待保养数"
              width="150"
              align="center"
              prop="sdmHmcsMaintain"
            />
            <el-table-column
              label="总累计模数"
              width="150"
              align="center"
              prop="sdmHmcsSum"
            />
          </el-table>
        </div>
        <div style="display: inline-block">
          <el-table
            style="width: 602px"
            v-loading="loading"
            border
            stripe
            highlight-current-row
            :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
            :data="mjmProductionList2"
            height="414px"
          >
            <el-table-column
              label="日期"
              width="150"
              align="center"
              prop="sdmRq"
            />
            <el-table-column
              label="日生产模数"
              width="150"
              align="center"
              prop="sdmHmcs"
            />
            <el-table-column
              label="待保养数"
              width="150"
              align="center"
              prop="sdmHmcsMaintain"
            />
            <el-table-column
              label="总累计模数"
              width="150"
              align="center"
              prop="sdmHmcsSum"
            />
          </el-table>
        </div>
        <p style="width: 1200px; text-align: center">模具维修/保养记录</p>
        <div style="display: inline-block">
          <el-table
            style="width: 602px"
            v-loading="loading"
            border
            stripe
            highlight-current-row
            :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
            :data="mjmMaintainLeftList"
            height="200px"
          >
            <el-table-column
              label="日期"
              width="150"
              align="center"
              prop="xmlJssj"
            >
              <template v-slot="scope">
                <span>{{ parseTime(scope.row.xmlJssj, "{m}月{d}日") }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="维修/保养内容"
              width="300"
              align="center"
              prop="xmlWxinf"
            >
              <template v-slot="scope">
                <span v-if="scope.row.xmlSxinf == 'B'">一级保养</span>
                <span v-else-if="scope.row.xmlSxinf == 'C'">二级保养</span>
                <span v-else-if="scope.row.xmlSxinf == 'D'">三级保养</span>
                <span v-else>{{ scope.row.xmlSxinf }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="结果"
              width="150"
              align="center"
              prop="xmlZtbz"
            >
              <template v-slot="scope">
                <span v-if="scope.row.xmlZtbz == '1'">进行中</span>
                <span v-else-if="scope.row.xmlZtbz == '2'">已完成</span>
                <span v-else-if="scope.row.xmlZtbz == '3'">已完成</span>
                <span v-else>{{ scope.row.xmlZtbz }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div style="display: inline-block">
          <el-table
            style="width: 602px"
            v-loading="loading"
            border
            stripe
            highlight-current-row
            :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
            :data="mjmMaintainRightList"
            height="200px"
          >
            <el-table-column
              label="日期"
              width="150"
              align="center"
              prop="xmlJssj"
            >
              <template v-slot="scope">
                <span>{{ parseTime(scope.row.xmlJssj, "{m}月{d}日") }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="维修/保养内容"
              width="300"
              align="center"
              prop="xmlWxinf"
            >
              <template v-slot="scope">
                <span v-if="scope.row.xmlSxinf == 'B'">一级保养</span>
                <span v-else-if="scope.row.xmlSxinf == 'C'">二级保养</span>
                <span v-else-if="scope.row.xmlSxinf == 'D'">三级保养</span>
                <span v-else>{{ scope.row.xmlSxinf }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="结果"
              width="150"
              align="center"
              prop="xmlZtbz"
            >
              <template v-slot="scope">
                <span v-if="scope.row.xmlZtbz == '1'">进行中</span>
                <span v-else-if="scope.row.xmlZtbz == '2'">已完成</span>
                <span v-else-if="scope.row.xmlZtbz == '3'">已完成</span>
                <span v-else>{{ scope.row.xmlZtbz }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-dialog>

    <!-- 添加或修改模具资料信息对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      :rules="rules"
      :close-on-click-modal="false"
      :before-close="handleClose"
      draggable
      width="800px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="12">
          <el-form-item label="模具编号" prop="mjmMjbh">
            <el-input
              v-model="form.mjmMjbh"
              placeholder="请输入模具编号"
              :disabled="isUpdate"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="模具名称" prop="mjmMjmc">
            <el-input v-model="form.mjmMjmc" placeholder="请输入模具名称" />
          </el-form-item>
        </el-col>
        <el-col :span="3" style="margin-right: 30px">
          <el-form-item
            label="模具尺寸（mm）"
            label-width="130px"
            prop="mjmMjgg"
          >
            <!--            <el-input v-model="form.mjmMjgg" placeholder="请输入模具尺寸"/>-->
          </el-form-item>
        </el-col>
        <el-col
          :span="4"
          style="
            margin-bottom: 22px;
            display: flex;
            line-height: 34px;
            height: 34px;
          "
        >
          <span style="margin-right: 8px">长</span>
          <el-input v-model="form.mjmCd" @input="getContainer" />
        </el-col>
        <el-col
          :span="4"
          style="
            margin-bottom: 22px;
            display: flex;
            line-height: 34px;
            height: 34px;
          "
        >
          <span style="margin: 0 8px 22px">宽</span>
          <el-input v-model="form.mjmKd" @input="getContainer" />
        </el-col>
        <el-col
          :span="4"
          style="
            margin-bottom: 22px;
            display: flex;
            line-height: 34px;
            height: 34px;
          "
        >
          <span style="margin: 0 8px">厚</span>
          <el-input v-model="form.mjmGd" @input="getContainer" />
        </el-col>
        <el-col :span="8" style="margin-bottom: 22px">
          <el-input v-model="form.mjmMjgg" @input="getContainer" disabled />
        </el-col>

        <el-col :span="5">
          <el-form-item label="模具状态" prop="mjmMjzt">
            <el-select v-model="form.mjmMjzt" placeholder="请选择模具状态">
              <el-option
                v-for="dict in mjmMjztOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="存放位置" prop="mjmCwdm">
            <el-input v-model="form.mjmCwdm" placeholder="请输入存放位置" />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="吨位" prop="mjmDw">
            <el-input-number
              :controls="false"
              v-model="form.mjmDw"
              @blur="setMjmByzq(form.mjmDw)"
              placeholder="0"
              :precision="0"
              style="width: 60px"
            />
            T
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="共模描述" prop="mjmXsms">
            <el-input v-model="form.mjmXsms" placeholder="请输入共模描述" />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="穴数" prop="mjmXs">
            <el-input v-model="form.mjmXs" />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="到厂日期" prop="mjmDcrq">
            <el-date-picker
              clearable
              size="small"
              v-model="form.mjmDcrq"
              type="date"
              :clearable="false"
              value-format="yyyy-MM-dd"
              placeholder="选择到厂日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <el-form-item label="成型时间" prop="mjmCxsj">
            <el-input v-model="form.mjmCxsj" placeholder="请输入成型时间" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="模具厂商" prop="mjmMjcs">
            <el-input v-model="form.mjmMjcs" placeholder="请输入模具厂商" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="热流道商" prop="mjmRldcs">
            <el-input
              v-model="form.mjmRldcs"
              placeholder="请输入热流道供应商"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属客户" prop="mjmKhid">
            <el-select
              v-model="form.mjmKhid"
              @change="handleJzByCusId"
              filterable
              placeholder="请选择所属客户"
            >
              <el-option
                v-for="dict in mjmKhOptions"
                :key="dict.cusId"
                :label="dict.cusName"
                :value="dict.cusId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="机种代码" prop="mjmJzid">
            <el-select
              v-model="form.mjmJzid"
              filterable
              placeholder="请选择机种代码"
            >
              <el-option
                v-for="dict in mjmJzmOptions"
                :key="dict.jzmId"
                :label="dict.jzmJzdm"
                :value="dict.jzmId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="保养周期" prop="mjmByzq">
            <el-input v-model="form.mjmByzq" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="使用寿命" prop="mjmSysm">
            <el-input v-model="form.mjmSysm" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="配套设备" prop="mjmMjsb">
            <el-input v-model="form.mjmMjsb" placeholder="请输入模具配套设备" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="mjmDesc">
            <el-input v-model="form.mjmDesc" placeholder="请输入备注" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 上传对话框 -->
    <el-dialog
      :title="title"
      v-model="openStr"
      :close-on-click-modal="false"
      draggable
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="模具编号">
          <el-input v-model="selectMjbh" disabled />
        </el-form-item>
        <el-form-item label="模具名称">
          <el-input v-model="selectMjmc" disabled />
        </el-form-item>
        <el-form-item label="文件名称" prop="mjmFile">
          <el-input
            v-model="form.mjmFile"
            placeholder="请输入文件名称"
            @input="upLoadFile"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.mjmDesc" placeholder="请输入备注名称" />
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; flex-direction: row-reverse"
      >
        <el-button @click="cancel">取 消</el-button>
        <el-upload
          action="#"
          :http-request="requestUpload"
          :show-file-list="false"
          :before-upload="beforeUpload"
          :disabled="upLoading"
        >
          <el-button :disabled="upLoading">
            上传
            <i class="el-icon-upload el-icon--right"></i>
          </el-button>
        </el-upload>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listMjmMstr,
  getMjmMstr,
  delMjmMstr,
  addMjmMstr,
  updateMjmMstr,
  exportMjmMstr,
  treeSelect,
  uploadMjm,
  listFile,
  getMjmByMjbh,
  listMjmProductionModulus,
  listRepairAndMaintain,
} from "@/api/project/mjmMstr";
import { getAllCustomerTwo } from "@/api/project/customer";
import { getAllJzm, getJzByCusId } from "@/api/project/jzmMstr";
import { delDocList } from "@/api/project/docList";
import { listModelByMjbh } from "@/api/device/modelRepair";

export default {
  name: "MjmMstr",
  data() {
    return {
      upLoading: true,
      activeTab: "first",
      upLoadButton: true,
      //下载内容
      upDateContainer: null,
      selectMjmc: String,
      selectMjbh: String,
      selectMjbhs: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      //禁用修改模具编号
      isUpdate: false,
      // 根据名称筛选部门树
      deptName: null,
      // 部门树选项
      deptOptions: [],
      treeLoad: true,
      curNodeKey: null,
      expandedKey: [0],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 模具资料信息表格数据
      mjmMstrList: [],
      mjmMstrProList: {},
      mjmMaintainLeftList: [],
      mjmMaintainRightList: [],
      mjmProductionList: [],
      mjmProductionList2: [],
      //上传文件记录数据
      mjmFileList: [],
      // 保养维修记录
      mjmBylXmlList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openSearch: false,
      openResume: false,
      //上传对话框
      openStr: false,
      tableH: 1,
      tableHTree: 1,
      tableHChild: 1,
      // 模具状态字典
      mjmMjztOptions: [],
      //客户所有客户字典
      mjmKhOptions: [],
      //分页 需要的 参数
      clickMjmJzid: null,
      clickMjmKhid: null,
      //机种字典
      mjmJzmOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mjmMjbh: null,
        mjmMjmc: null,
        mjmMjzt: null,
        mjmJzid: null,
        mjmKhid: null,
      },
      //树参数
      queryTrees: {
        mjmJzid: null,
        mjmKhid: null,
      },
      // 表单参数
      form: {},
      formYearAndMonth: {
        recentYear: "",
        recentMonth: "",
      },
      // 表单校验
      rules: {
        mjmMjbh: [
          { required: true, message: "模具编号不能为空", trigger: "blur" },
        ],
        mjmMjmc: [
          { required: true, message: "模具名称不能为空", trigger: "blur" },
        ],
        mjmFile: [
          { required: true, message: "文件名称不能为空", trigger: "blur" },
        ],
        mjmCxsj: [
          { required: true, message: "成型时间不能为空", trigger: "blur" },
        ],
        mjmKhid: [
          { required: true, message: "请选择所属客户", trigger: "blur" },
        ],
        mjmXs: [{ required: true, message: "穴数不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getTreeselect();
    this.getList();
    this.init();
    this.getDicts("mould_status").then((response) => {
      this.mjmMjztOptions = response.data;
    });
    getAllCustomerTwo().then((response) => {
      this.mjmKhOptions = response.data;
      for (let i of this.mjmKhOptions) {
        i.dictLabel = i.cusName;
        i.dictValue = i.cusId + "";
      }
    });
    getAllJzm().then((response) => {
      this.mjmJzmOptions = response.data;
    });
  },
  methods: {
    init() {
      var myDate = new Date();
      var year = myDate.getFullYear(); //获取当前年
      var months = myDate.getMonth() + 1; //获取当前月
      this.initSelectYear(year - 30);
      this.initSelectMonth(months);
      this.formYearAndMonth.recentYear = year;
      this.formYearAndMonth.recentMonth = months;
    },
    initSelectYear(year) {
      this.years = [];
      for (let i = 0; i <= 30; i++) {
        this.years.push({ value: year + i, label: year + i + "年" });
      }
    },
    initSelectMonth(months) {
      this.months = [];
      for (let i = 1; i <= 12; i++) {
        this.months.push({ value: i, label: i + "月" });
      }
    },
    yearChange(value) {
      this.formYearAndMonth.recentYear = value;
      // 刷新记录
      this.refreshMoldRecord(this.mjmMstrProList.mjmMjbh);
    },
    monthChange(value) {
      this.formYearAndMonth.recentMonth = value;
      // 刷新记录
      this.refreshMoldRecord(this.mjmMstrProList.mjmMjbh);
    },
    handleImgLook(a) {
      let files = process.env.VUE_APP_BASE_API + a.docPath;
      window.open(files);
    },
    requestUpload() {},
    upLoadFile(a) {
      if (a) {
        this.upLoading = false;
      } else {
        this.upLoading = true;
      }
    },
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //生产-绿色
      if (row.mjmMjzt == "SC") {
        return "color:#09aa46";
      }
      //报废-灰色
      if (row.mjmMjzt == "BF") {
        return "color:#999291";
      }
      //外发-紫色
      if (row.mjmMjzt == "WF") {
        return "color:#a503bb";
      }
      //维修-红色
      if (row.mjmMjzt == "WX") {
        return "color:#c70c05";
      }
    },
    // 上传预处理
    beforeUpload(file) {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => {
        this.upDateContainer = reader.result;
        let formData = new FormData();

        formData.append("mjbh", this.selectMjbh);
        formData.append("fileName", this.form.mjmFile);
        formData.append("docType", "D");
        formData.append("desc", this.form.mjmDesc);
        formData.append("file", file);
        uploadMjm(formData).then((response) => {
          this.queryTrees.docMjbh = this.selectMjbh;
          this.queryTrees.docType = "D";
          const query = this.queryTrees;
          this.mjmFile(query);
          this.$message.success("文件上传成功");
          this.openStr = false;
          this.upLoading = true;
        });
      };
    },

    /** 模具履历表点击事件 */
    resume(row) {
      // 模具基础信息
      getMjmByMjbh(row).then((res) => {
        this.mjmMstrProList = res.data;
      });
      // 刷新记录
      this.refreshMoldRecord(row.mjmMjbh);
    },
    /** 刷新保养记录和维修记录 */
    refreshMoldRecord(mjmMjbh) {
      // 日保养记录等
      listMjmProductionModulus(
        mjmMjbh,
        this.formYearAndMonth.recentYear,
        this.formYearAndMonth.recentMonth
      ).then((res) => {
        res.data.list1 = res.data.list1.map((a) => {
          a.sdmRq = this.$moment(a.sdmRq).format("MM月DD日");
          return a;
        });
        res.data.list2 = res.data.list2.map((a) => {
          a.sdmRq = this.$moment(a.sdmRq).format("MM月DD日");
          return a;
        });
        res.data.list2[res.data.list2.length - 1].sdmRq = "本月累计";
        this.mjmProductionList = res.data.list1;
        this.mjmProductionList2 = res.data.list2;
      });
      // 维修/保养记录
      listModelByMjbh(
        mjmMjbh,
        this.formYearAndMonth.recentYear,
        this.formYearAndMonth.recentMonth
      ).then((res) => {
        this.mjmMaintainLeftList = res.data.repairList;
        this.mjmMaintainRightList = res.data.maintainList;
        this.openResume = true;
      });
    },
    getContainer() {
      if (
        this.form.mjmCd === null ||
        this.form.mjmKd === null ||
        this.form.mjmGd === null ||
        this.form.mjmCd === "" ||
        this.form.mjmKd === "" ||
        this.form.mjmGd === ""
      ) {
        return;
      }
      this.form.mjmMjgg =
        (this.form.mjmCd ? this.form.mjmCd + "*" : "") +
        (this.form.mjmKd ? this.form.mjmKd + "*" : "") +
        (this.form.mjmGd ? this.form.mjmGd + "*" : "");
      this.form.mjmMjgg = this.form.mjmMjgg.slice(
        0,
        this.form.mjmMjgg.length - 1
      );
    },
    getTreeselect() {
      treeSelect().then((response) => {
        const tree = this.$refs.tree;
        const tmpKey = tree.getCurrentKey();
        if (tmpKey) {
          this.expandedKey = [tmpKey];
          this.$nextTick(() => {
            tree.setCurrentKey(tmpKey);
          });
        }
        var tmp = [];
        tmp.push(Object.assign({}, this.deptOptions[0], response.data));
        this.deptOptions = tmp;
        //this.treeLoad = true
      });
    },
    // 节点单击事件
    handleNodeClick(data) {
      // 点击会刷新搜索条件
      this.queryParams.mjmMjbh = null;
      this.queryParams.mjmMjmc = null;
      this.queryParams.mjmMjzt = null;

      this.allName = data.label;
      if (data.parentId == null) {
        this.queryParams.mjmKhid = data.id;
        this.queryParams.mjmJzid = null;
        this.queryParams.pageNum = 1;
        this.clickMjmKhid = data.id;
        this.clickMjmJzid = null;
      } else {
        this.queryParams.pageNum = 1;
        this.queryParams.mjmJzid = data.id;
        this.queryParams.mjmKhid = data.parentId;
        this.clickMjmJzid = data.id;
        this.clickMjmKhid = data.parentId;
        // console.log(this.queryParams)
      }
      listMjmMstr(this.queryParams).then((response) => {
        this.mjmMstrList = response.rows;
        this.total = response.total;
        this.loading = false;
        // this.queryParams.mjmJzid = null
        // this.queryParams.mjmKhid = null
      });
    },
    clickListFile(row) {
      this.queryTrees.docMjbh = row.mjmMjbh;
      if (this.queryTrees.docMjbh == null) {
        this.queryTrees.docMjbh = row.docMjbh;
      }
      this.queryTrees.docType = "D";
      const query = this.queryTrees;
      this.mjmFile(query);
      listRepairAndMaintain({ mjmMjbh: row.mjmMjbh }).then((response) => {
        this.mjmBylXmlList = response.data;
      });
    },
    handleSearch() {
      this.reset();
      this.title = "查询模具资料信息";
      this.openSearch = true;
    },
    /** 得到文件 */
    mjmFile(query) {
      listFile(query).then((response) => {
        this.mjmFileList = response.rows;
      });
    },
    /** 查询模具资料信息列表 */
    getList() {
      this.loading = true;
      this.tableHTree = document.body.clientHeight - 155;
      this.tableH = this.tableHTree / 2 + 15;
      this.tableHChild = this.tableH - 50;
      this.queryParams.pageSize = this.tableH > 350 ? 15 : 10;
      this.$nextTick(() => {
        this.$refs.tree.store.defaultExpandAll = false;
      });
      listMjmMstr(this.queryParams).then((response) => {
        this.mjmMstrList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      //this.getTreeselect()
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openStr = false;
      this.isUpdate = false;
      this.openSearch = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        mjmId: null,
        mjmMjbh: null,
        mjmMjmc: null,
        mjmFile: null,
        mjmMjgg: null,
        mjmCd: 0,
        mjmKd: 0,
        mjmGd: 0,
        mjmDw: 0,
        mjmXs: 0,
        mjmCxsj: null,
        mjmCwdm: null,
        mjmJzid: null,
        mjmKhid: null,
        mjmMjzt: null,
        mjmType: null,
        mjmNewjtbh: null,
        mjmNewbbdm: null,
        mjmNewsxsj: null,
        mjmCount: null,
        mjmDesc: null,
        mjmMjsb: null,
        mjmByzq: 0,
        mjmSysm: 0,
        mjmXsms: null,
        mjmDcrq: null,
        mjmMjcs: null,
        mjmRldcs: null,
        mjmYbys: null,
        mjmTreeparent: null,
        mjmTreechildren: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        mjmCpmc: null,
        mjmKhbm: null,
      };
      this.resetForm("form");
    },
    handleClose() {
      this.open = false;
      this.openResume = false;
      this.isUpdate = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.mjmId);
      this.selectMjbh = selection.map((item) => item.mjmMjbh)[0];
      this.selectMjbhs = selection.map((item) => item.mjmMjbh);
      this.selectMjmc = selection.map((item) => item.mjmMjmc)[0];
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加模具资料信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const mjmId = row.mjmId || this.ids;
      getMjmMstr(mjmId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.isUpdate = true;
        this.title = "修改模具资料信息";
      });
    },
    //上传
    upLoad() {
      this.reset();
      this.openStr = true;
    },
    /** 提交按钮 */
    submitForm() {
      if (
        this.form.mjmXs == null ||
        this.form.mjmXs <= 0 ||
        this.form.mjmCxsj == null ||
        this.form.mjmCxsj <= 0
      ) {
        this.msgError("穴数或成型时间不能小于0");
        return;
      } else {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (this.form.mjmId != null) {
              updateMjmMstr(this.form).then((response) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.isUpdate = false;
                this.getList();
                this.getTreeselect();
              });
            } else {
              addMjmMstr(this.form).then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
                this.getTreeselect();
              });
            }
          }
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const mjmIds = row.mjmId || this.ids;
      this.$confirm(
        '是否确认删除模具资料信息编号为"' + this.selectMjbhs + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delMjmMstr(mjmIds);
        })
        .then(() => {
          this.getList();
          this.getTreeselect();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 删除文件按钮操作 */
    handleFileDelete(row) {
      const djbh = row.docDjbh;
      this.$confirm(
        '是否确认删除文件编号为"' + djbh + '"的数据记录及文件?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delDocList(djbh);
        })
        .then(() => {
          this.clickListFile(row);
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.queryParams.mjmJzid = this.clickMjmJzid;
      this.queryParams.mjmKhid = this.clickMjmKhid;
      this.getList();
    },
    handleJzByCusId(id) {
      this.form.mjmJzid = null;
      //暂时回归老系统
      getJzByCusId(id).then((res) => {
        this.mjmJzmOptions = res.data;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有模具资料信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportMjmMstr(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    setMjmByzq(mjmDw) {
      if ((this.title = "添加模具资料信息")) {
        this.form.mjmSysm = 500000;
      }

      if (mjmDw < 600) {
        this.form.mjmByzq = 80000;
      } else if (mjmDw < 1200) {
        this.form.mjmByzq = 50000;
      } else {
        this.form.mjmByzq = 30000;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.el-table .cell {
  white-space: nowrap;
}
::v-deep .divmjlvb {
  text-align: center;
  .tabJbxx,
  .el-table {
    border: 1px solid rgb(96, 98, 102);
    border-collapse: collapse;
    display: inline-block;
    td,
    th {
      border-bottom: 1px solid rgb(96, 98, 102);
      border-right: 1px solid rgb(96, 98, 102);
    }
  }
}
</style>
